package com.perfect.controller;

import com.perfect.annotation.RequirePermission;
import com.perfect.base.BaseController;
import com.perfect.base.ResultInfo;
import com.perfect.query.ResolveOrQuery;
import com.perfect.service.ResolveOrService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author YU
 */
@Controller
@RequestMapping("resolve")
public class ResolveOrController extends BaseController {

    @Resource
    private ResolveOrService resolveOrService;

    /**
     * 跳转到退货单页面
     * @return
     */
    @RequirePermission(code = "706010")
    @RequestMapping("index")
    public String index(){
        return "orders/resolve.or";
    }

    /**
     * 展示退货申请列表
     * @param resolveOrQuery
     * @return
     */
    @RequirePermission(code = "706020")
    @RequestMapping("list")
    @ResponseBody
    public Map<String, Object> listResolveOR(ResolveOrQuery resolveOrQuery){
        System.out.println(resolveOrQuery);
        return resolveOrService.queryByParamsForTable(resolveOrQuery);
    }

    /**
     * 删除退货单
     * @param ids
     * @return
     */
    @RequirePermission(code = "706030")
    @RequestMapping("delete")
    @ResponseBody
    public ResultInfo delete(Integer ids){
        resolveOrService.deleteResolveOr(ids);
        return success("订单删除成功");
    }

    /**
     * 删除多个退货单
     * @param ids
     * @return
     */
    @RequirePermission(code = "706040")
    @RequestMapping("deleteMore")
    @ResponseBody
    public ResultInfo deleteMore(String ids){
        resolveOrService.deleteMoreResolveOr(ids);
        return success("订单删除成功");
    }

    /**
     * 处理退货单申请
     * @param id
     * @param state
     * @return
     */
    @RequirePermission(code = "706040")
    @RequestMapping("yesorno")
    @ResponseBody
    public ResultInfo resolveOr(Integer id, String state){
        resolveOrService.updateState(id, state);
        return success("退货单处理成功");
    }

    /**
     * 添加退货单备注
     * @param id
     * @param content
     * @return
     */
    @RequirePermission(code = "706050")
    @RequestMapping("content")
    @ResponseBody
    public ResultInfo content(Integer id, String content){
        resolveOrService.updateContent(id, content);
        return success("备注添加成功");
    }
}
